package com.zhuoshi.action;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.ServletRequestDataBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.InitBinder;

import com.zhuoshi.bean.Wd_ht_projectModel;
import com.zhuoshi.service.Wd_ht_projectModelService;

@Controller
@RequestMapping("/project")
public class Wd_ht_projectAction {
	
	@Autowired
	Wd_ht_projectModelService wd_ht_projectModelService ;
	
	@RequestMapping("/selectAll")
   public String selectAll(Wd_ht_projectModel record,Model model){
		List<Wd_ht_projectModel> wd_ht_projectList = wd_ht_projectModelService.selectAll(record);		
		model.addAttribute("wd_ht_projectList", wd_ht_projectList);
		return "Wd_ht_project" ;
   }
	
	@RequestMapping("/Wd_ht_project_toUpdate.do")
	public String wd_ht_project_toUpdate(Wd_ht_projectModel project,Model model){
		System.out.println(project.getProjectId());
		
		Wd_ht_projectModel bean = wd_ht_projectModelService.selectByPrimaryKey(project.getProjectId());
		model.addAttribute("bean", bean);
		return "Wd_ht_project_toUpdate" ;
	}
	
	
	
	@RequestMapping("/Wd_ht_project_update.do")
	public String wd_ht_project_update(Wd_ht_projectModel record){	
		 System.out.println("");
		 wd_ht_projectModelService.updateByPrimaryKeySelective(record);		
		return "redirect:/project/selectAll.do" ;
	}
	
	@RequestMapping("/Wd_ht_project_toAdd.do")
	public String wd_ht_project_toAdd(){		 
		return "Wd_ht_project_add" ;
	}
	
	@RequestMapping("/Wd_ht_project_add.do")
	public String wd_ht_project_add(Wd_ht_projectModel record){	
		wd_ht_projectModelService.insertSelective(record);
		return "redirect:/project/selectAll.do" ;
	}
	
	@RequestMapping("/Wd_ht_project_delete.do")
	public String wd_ht_project_delete(String projectId){
		wd_ht_projectModelService.deleteByPrimaryKey(projectId);
		return "redirect:/project/selectAll.do" ;
	}
	
	
	@InitBinder
	public void InitBinder(ServletRequestDataBinder binder){
		binder.registerCustomEditor(Date.class, 
				new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"), true));
		
	}
}
